﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace Projekt_GUI.Forms
{
    public partial class Buchung_SelectKunde : Form
    {
        public Buchung_SelectKunde()
        {
            InitializeComponent();
        }

        private void Buchung_SelectKunde_Load(object sender, EventArgs e)
        {
            try
            {
                using (OracleConnection con = new OracleConnection("Data Source=localhost; User Id=PROJEKT; Password=PROJEKT"))
                {
                    con.Open();
                    OracleCommand com = con.CreateCommand();
                    com.CommandText = "SELECT NAME,VORNAME,NUMMER FROM Kunden";

                    OracleDataReader r = com.ExecuteReader();

                    int counter = 0;
                    listView1.Items.Clear();
                    while (r.Read())
                    {
                        listView1.Items.Add(r.GetValue(0).ToString());
                        listView1.Items[counter].SubItems.Add(r.GetValue(1).ToString());
                        listView1.Items[counter].SubItems.Add(r.GetValue(2).ToString());
                        counter++;
                    }
                }
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message, "Oracle Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(listView1.SelectedItems.Count > 0)
            {
                Form1.KundenID = listView1.SelectedItems[0].SubItems[2].Text;
                Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1.KundenID = "";
            Close();
        }
    }
}
